﻿
@{
    ViewData["Title"] = "多选激活QuireAllEdit";
}

@section Scripts
    {
    <link href="~/css/page.css" rel="stylesheet" />
    <script type="text/javascript">
        var selfLayer = null, page = 1, active = null;
        layui.use(['layer', 'table', 'laydate'], function () {
            var layer = layui.layer //弹层
                ,
                table = layui.table, form = layui.form; //表格
            layui.laydate.render({
                elem: '#RecordTime',
                type: 'month',
                range: true
            })

            //产品类别
            picker.GetTypeList(layui.form, { type: "产品类型" }, $("#typeId").val());
            form.on("select(Type)", function (data) {
                axios.get('/SpeciesManage/GetSpeciesManageTree', {
                    params: {
                        type: data.value
                    }
                }).then(function (result) {
                    console.log("258");
                    console.log(result.data.result.data);
                    if (result.data.code == 200) {
                        var options = '<option value="">请选择种类</option>';
                        var resultdata = result.data.result.data;
                        if (resultdata != null) {
                            for (var i = 0; i < resultdata.length; i++) {
                                if (data.value == resultdata[i].type)
                                    options += '<option value="' + resultdata[i].id + '" selected>' + resultdata[i].name + '</option>';
                                else
                                    options += '<option value="' + resultdata[i].id + '">' + resultdata[i].name + '</option>';
                            }
                        }

                        if ($("#speciesManage"))
                            $("#speciesManage").html(options);
                        if ($("#speciesManage"))
                            $("#speciesManage").html(options);
                        form.render();
                    } else {
                        alert(result.data.msg)
                    }

                }).catch(function (error) {
                    console.log(error);
                });
            })

            var tableData=[];

            //执行一个 table 实例
            table.render({
                id: 'dataList',
                elem: '#dataview',
                height: 'full-80',
                url: "/SignageApplication/GetIdentificationAll",
                headers: { 'Authorization': 'Bearer ' + localStorage.getItem("X-TOKEN") },
                where: { status: "1" },
                request: {
                    pageName: 'index' //页码的参数名称，默认：page
                    , limitName: 'size' //每页数据量的参数名，默认：limit
                },
                parseData: function (res) { //res 即为原始返回的数据
                    console.log(res);
                    return {
                        "code": res.code, //解析接口状态
                        "msg": res.msg, //解析提示文本
                        "count": res.total, //解析数据长度
                        "data": res.result.data //解析数据列表
                    };
                },
                response: {
                    statusCode: 200 //规定成功的状态码，默认：0
                },
                done: function (res, curr, count) {
                    page = curr;
                },
                page: true,
                cols: [
                    [
                        {type: 'checkbox', fixed: 'left'},
                        { field: 'signageApplicationNo', title: '所属申请单', width: '20%' },
                        { field: 'packageNo', title: '批量码', width: '20%' },
                        { field: 'qrCode', title: '标识二维码', width: '20%' },
                        { field: 'typeName', title: '产品类别', width: '15%' },
                        { field: 'speciesName', title: '产品名称', width: '15%' },
                        { field: 'logoStockNo', title: '标识号', width: '10%' },
                        { field: 'enterpriseName', title: '所属企业', width: '10%' },
                        {
                            field: 'registeredTime', title: '配发时间', width: '10%',
                             templet : "<div>{{layui.util.toDateString(d.registeredTime, 'yyyy年MM月dd日')}}</div>"
                        }
                        //  { title: '状态', align: 'center', toolbar: '#remarks', width: '10%' },
                    ]
                ]
            });
            //执行二个 table 实例
            table.render({
                id: 'dataList1',
                elem: '#dataview1',
                height: 'full-80',
                data:tableData,
               // url: "/LogoStock/GetLogoInputStockAll",
               // headers: { 'Authorization': 'Bearer ' + localStorage.getItem("X-TOKEN") },
               // where: { status: "3" },
                request: {
                    pageName: 'index' //页码的参数名称，默认：page
                    , limitName: 'size' //每页数据量的参数名，默认：limit
                },
                parseData: function (res) { //res 即为原始返回的数据
                    console.log(res);
                    return {
                        "code": res.code, //解析接口状态
                        "msg": res.msg, //解析提示文本
                        "count": res.total, //解析数据长度
                        "data": res.result.data //解析数据列表
                    };
                },
                response: {
                    statusCode: 200 //规定成功的状态码，默认：0
                },
                done: function (res, curr, count) {
                    page = curr;
                },
                page: true,
                cols: [
                    [
                        {type: 'checkbox', fixed: 'left'},
                        { field: 'signageApplicationNo', title: '所属申请单', width: '20%' },
                        { field: 'packageNo', title: '批量码', width: '20%' },
                        { field: 'qrCode', title: '标识二维码', width: '20%' },
                        { field: 'typeName', title: '产品类别', width: '15%' },
                        { field: 'speciesName', title: '产品名称', width: '15%' },
                        { field: 'logoStockNo', title: '标识号', width: '10%' },
                        { field: 'enterpriseName', title: '所属企业', width: '10%' },
                        {
                            field: 'registeredTime', title: '配发时间', width: '10%',
                             templet : "<div>{{layui.util.toDateString(d.registeredTime, 'yyyy年MM月dd日')}}</div>"
                        }
                        //  { title: '状态', align: 'center', toolbar: '#remarks', width: '10%' },
                    ]
                ]
            });

            var $b = layui.$;
            active = {
                reload: function (page) {
                    //执行重载
                    table.reload('dataList', {
                        page: {
                            curr: page || 1 //重新从第 1 页开始
                        },
                        where: {
                            sasearch: $("#keyword").val(),
                        }
                    });
                }
            };
            $b('#search').on('click', function () {
                var type = $b(this).data('type');
                active[type] ? active[type].call(this) : '';
            });
            //添加
            $b('#tableAdd').on('click', function () {
                var checkStatus = table.checkStatus('dataList');
                console.log(checkStatus.data);
                var obj = {};
                tableData = tableData.concat(checkStatus.data).reduce(function(item, next) {
                      obj[next.qrCode] ? '' : obj[next.qrCode] = true && item.push(next);
                      return item;
                }, []);
                table.reload('dataList1', {
                    data:tableData,
                    });
            });
            //清除
            $b('#tableClear').on('click', function () {
                tableData = [];
                table.reload('dataList1', {
                    data:tableData,
                    });
            });
            //提交
            $b('#allotmentAdd').on('click', function () {
                   axios({
                    method: 'post',
                    url: '/SignageApplication/UpdateActivationAll',
                    //  contentType: 'application/x-www-form-urlencoded',
                    data: tableData,
                    headers: { 'Authorization': 'Bearer ' + localStorage.getItem("X-TOKEN") }
                }) .then(function (response) {
                        console.log(response);
                        if (response.data.code == 200) {
                            javascript: history.go(-1);
                        } else {
                            alert(response.data.msg)
                        }

                    }).catch(function (error) {
                        console.log("添加失败!" + error);
                    });
            });
        });

    </script>
}

<blockquote class="layui-elem-quote layui-text layui-form">
    <div class="layui-inline">
        <label class="layui-form-label">关键字：</label>
        <div class="layui-input-inline">
            <input type="text" class="layui-input" id="keyword" name="keyword" style="width:210px" placeholder="">
        </div>
    </div>
    <div class="layui-inline">
        <label class="layui-form-label">产品类别：</label>
        <div class="layui-input-inline">
            <select id="Type" name="modules" lay-verify="required" lay-filter="Type" lay-search="">
            </select>
        </div>
    </div>
    <div class="layui-inline">
        <label class="layui-form-label">所属产品：</label>
        <div class="layui-input-inline">
            <select id="speciesManage" name="modules" lay-verify="required" lay-filter="speciesManage" lay-search="">
            </select>
        </div>
    </div>
    <div class="layui-inline">
        <div class="layui-form-label">
            <button class="layui-btn" id="search" style="width: 60px; height: 28px; line-height: 28px; display: inline" data-type="reload">搜索</button>
        </div>
    </div>
    <div class="layui-inline">
        <div class="layui-form-block">
            <a asp-action="ActivationList" class="layui-btn layui-btn-primary backIframe" style="width: 90px; height: 28px; line-height: 28px;">返回</a>
        </div>
    </div>
    <div class="layui-inline">
        <div class="layui-form-label">
            <button class="layui-btn" id="allotmentAdd" style="width: 60px; height: 28px; line-height: 28px; display: inline" data-type="reload">提交</button>
        </div>
    </div>
</blockquote>
<div class="layui-form-item" style="width:100%; display:flex;">
    @*<label class="layui-form-label">申请企业</label>
        <div class="" style="padding-left:10px">
            <input type="text" class="layui-input w_545" style="width:210px" disabled autocomplete="off" id="enterpriseName">
        </div>
        <label class="layui-form-label">已配发数量</label>
        <div class="" style="padding-left:10px">
            <input type="text" class="layui-input w_545" disabled id="enterpriseQuantity">
        </div>*@
</div>
<div style="display:flex; padding:0 10px; box-sizing:border-box;">
    <div style="width:50%;float:right;"><table class="layui-hide" id="dataview" lay-filter="datalist"></table></div>
    <div style="width:70px;margin:auto 5px; height: 56px;">
        <button class="layui-btn" id="tableAdd" style="width: 60px; height: 28px; line-height: 28px; display: block;margin:10px 0;" data-type="reload">添加</button>
        <button class="layui-btn" id="tableClear" style="width: 60px; height: 28px; line-height: 28px; display: block;margin:10px 0;" data-type="reload">清空</button>
    </div>
    <div style="width:50%;float:left;"><table class="layui-hide" id="dataview1" lay-filter="datalists"></table></div>
</div>


